﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stardust.Common.Utils
{
    public static class HttpHelper
    {
        public static string PostJsonToUrl(string url, object data, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.PostJsonToUrl(url, data, (request) =>
            {
                request.Timeout = timeout;
            });
        }

        public static Task<string> PostJsonToUrlAsync(string url, object data, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.PostJsonToUrlAsync(url, data, (request) =>
            {
                request.Timeout = timeout;
            });
        }

        public static string PostJsonToUrl(string url, string json, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.PostJsonToUrl(url, json, (request) =>
            {
                request.Timeout = timeout;
            });
        }

        public static Task<string> PostJsonToUrlAsync(string url, string json, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.PostJsonToUrlAsync(url, json, (request) =>
            {
                request.Timeout = timeout;
            });
        }

        public static string GetStringFromUrl(string url, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.GetStringFromUrl(url, "*/*", (request) =>
            {
                request.Timeout = timeout;
            });
        }

        public static Task<string> GetStringFromUrlAsync(string url, int timeout = 6000)
        {
            return ServiceStack.HttpUtils.GetStringFromUrlAsync(url, "*/*", (request) =>
            {
                request.Timeout = timeout;
            });
        }
    }
}
